home *** CD-ROM | disk | FTP | other *** search
/ boe.pres.k12.wv.us / boe.pres.k12.wv.us.zip / boe.pres.k12.wv.us / Utilities / Xerox Workcentre 5335 / Windows Scan / 64-bit_x64 / Russian / cpsimage.cab / data / xipScripts / hlDemo.elf next >
Text File  |  2009-04-23  |  3KB  |  103 lines

  1. /*
  2. ** This script demonstrates XIPS highlighted text extraction. It reads
  3. ** image files from a specified input directory. For each image file, it
  4. ** extracts the highlighted text regions into separate images, and then writes
  5. ** these text extraction images to a specified output directory.
  6. */
  7.  
  8. // Load scripted support procedures
  9. #load "xipProcs/hlExtract.proc";
  10.  
  11.  
  12. // Imported parameters
  13. IMPORT STRING     inpath     = ".";
  14. IMPORT STRING     outpath    = ".";
  15. IMPORT STRING     pattern    = "*.*";
  16. IMPORT ELFBOOLEAN display    = 1;
  17. IMPORT ELFBOOLEAN save       = 0;
  18.  
  19. XIPIMAGE imgIn, imgOut;
  20. ELFLIST  output;
  21. STRING   infileList;
  22. STRING   infile;
  23. STRING   outfile;
  24. STRING   label;
  25. INTEGER  nOutputs;
  26. INTEGER  done;
  27. INTEGER  i;
  28.  
  29. print "XIPS Highlighted Text Extraction Demo";
  30.  
  31. // Register image processing classes
  32. LoadClasses (filename: "xeng");
  33.  
  34. // Check for invalid input file path
  35. if (!IsDir (filename: inpath)) {
  36.   print "ERROR: Input file path does not exist";
  37.   return;
  38. }
  39. print "  Input file path: " + inpath;
  40.  
  41. // Check for invalid output file path
  42. if (!IsDir (filename: outpath)) {
  43.   print "ERROR: Output file path does not exist";
  44.   return;
  45. }
  46. print "  Output file path: " + outpath;
  47.  
  48. // Append slash to input file path if necessary
  49. if (inpath.index (val: inpath.length () - 1) != "/")
  50.   inpath = inpath + "/";
  51.  
  52. // Append slash to output file path if necessary
  53. if (outpath.index (val: outpath.length () - 1) != "/")
  54.   outpath = outpath + "/";
  55.  
  56. // Get list of files from input file path
  57. infileList = System (cmd: "ls " + inpath + pattern, mode: "r");
  58. print "  Input file pattern: " + pattern;
  59.  
  60. // Process each file in input files list
  61. for (done=0; !done;) {
  62.   // Get next input filename
  63.   infile = infileList.getLine ();
  64.   if (!infile) {
  65.     done = 1;
  66.   } else {
  67.     // Read input image
  68.     imgIn = readimage (filename: infile).exec ();
  69.     print "  Processing " + infile + "...";
  70.  
  71.     // Extract highlighted text regions from input image
  72.     output = XIPHighlightExtract (input: imgIn);
  73.  
  74.     // Report number of text extraction images
  75.     nOutputs = output.length ();
  76.     print "    Number of text extraction images: " + nOutputs;
  77.  
  78.     // No text extraction images, process next input image
  79.     if (nOutputs == 0)
  80.       continue;
  81.  
  82.     // Process each text extraction image
  83.     for (i=0; i<nOutputs; i++) {
  84.       imgOut = output[i];
  85.  
  86.       // Display and/or save text extraction image
  87.       if (display || save) {
  88.         label = imgOut.info;
  89.         label.getToken ();
  90.         outfile = infile.name () + "_text_" + i + "_"
  91.                     + label.getToken () + "." + infile.ext ();
  92.  
  93.         if (display)
  94.           imgOut.display (title: outfile);
  95.  
  96.         if (save)
  97.           imgOut.writeint (filename: outpath + outfile);
  98.       }
  99.     }
  100.   }
  101. }
  102.  
  103.